﻿ 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Skybot.Logs.Broken
{
    class Program
    {
        static void Main(string[] args)
        {
            //测试写入();
            //多个文件写入测试
            var test =new FileWriteToDiskTest();
            test.Init();
            test.多Supple写入测试();
            System.Threading.Thread.Sleep(61 * 1000);
            //关闭超时文件
            test.CheckTimeOutCloseFile();
            //超时关闭所有文件
            Console.Read();
        }
        public static string HexPackeg = "232302FE4C4E4253434233465845443134333239330003AF0F06030E043401005B01015B0EC40EC40EC40EC40ED80EC40ED80EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40ED80EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40ED80ED80EC40EC40ED80EC40EC40EC40EC40EC40ED80EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40EC40200140101144A4A49494A49494949484A49494948484848484803003C000000000F0000025201EF5A0D6627100000000000000000040006F4560402609E20004400A1000000000501050ED801010EC401014A010A480D8827168E00AD271000000000000600000000008002807A4D09CAFBA25A383007236D9520041BF8010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000101010001000100010101000700000040010001000101070000F04101000101010001000100010101000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000101075C8F5A4101000100010001000101010001010101010101000100010101000100070000544207000034430700003443010001010100010101010100010001000101010001000100010001000100010001000100070000504207666666400100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000700000042070000084207F8537340077DAE72400700002041070000204107B81EAD430100010001010101010101000101070000C64201000700008C4201010100010007000040400100010001000100010001000100010001010101010001000100010001000167603B040244422E3032033C2F666C6173682F53442F4442432F4530303030383436325F433333444228323031345F455032295F424A5F736B5F323031343038303756392E646263EF";

        //日志名
        private static string logPathName = "BJEV-192.168.1.1 9000";
 
        public static void 测试写入()
        {
            ConnBrokenSupplements brokenlog = new ConnBrokenSupplements();
            brokenlog.Init(logPathName);
            int num = 1000000;
            int readNum = 0;

            byte[] arr = System.Text.ASCIIEncoding.ASCII.GetBytes(HexPackeg);
            Action act1 = () =>
            {

                for (int i = 0; i < num; i++)
                {
                    //发送数据
                    //brokenlog.Write(Guid.NewGuid().ToByteArray());
                    brokenlog.Write(arr);
                }
            };

            Action act2 = () =>
            {
                int filenum = 0;
                while (brokenlog.ReadBroken((b) =>
                {
                    readNum++;
                    return true;
                }, out filenum))
                {
                   Console.WriteLine("还有文件个数:" + filenum);
                    if (filenum == 0)
                    {
                        break;
                    }
                }
            };
            //多次循环写入数据.
            for (int i = 0; i < 3; i++)
            {
                readNum = 0;
                long time1 = act1.StopwatchRun();
                long time2 = act2.StopwatchRun();
               Console.WriteLine(string.Format("写入{0}条用时:{1}毫秒,{2:f2}/s", num, time1, num / (time1 / 1000.0)));
               Console.WriteLine(string.Format("读取{0}条用时:{1}毫秒,{2:f2}/s", readNum, time2, readNum / (time2 / 1000.0)));
               Console.WriteLine(string.Format("----------第{0}次循环结束", i));
            }

        }
    }
}
